package file;

import java.io.IOException;
import java.io.RandomAccessFile;

import org.junit.Test;

public class testRandomAccessFile {

	@Test
	public void testRandomAccessFilee2() throws IOException {

		RandomAccessFile randomAccess = new RandomAccessFile("hello.txt", "rw");

		String line = randomAccess.readLine();

		byte[] b = new byte[(int) (randomAccess.length() - line.length())];
		randomAccess.read(b);

		randomAccess.seek(line.length());

		randomAccess.writeBytes("\nhello\n");
		randomAccess.write(b);

		randomAccess.close();
	}

	@Test
	public void testRandomAccessFilee() throws IOException {

		RandomAccessFile randomAccess = new RandomAccessFile("hello.txt", "rw");

		String str = null;
		while ((str = randomAccess.readLine()) != null) {
			System.out.println(str);
		}

		// randomAccess.writeBytes("\nhello");
		// randomAccess.seek(18);
		// randomAccess.writeBytes("\nhello");
		randomAccess.close();
	}
}
